package com.itgungnir.designpattern.nullobject;

public class UserFactory {
	private static final String[] NAME_LIMIT = { "Jack", "Rose", "Tom" };

	private static UserFactory instance;

	private UserFactory() {
	}

	public static UserFactory getInstance() {
		if (instance == null) {
			synchronized (UserFactory.class) {
				if (instance == null) {
					instance = new UserFactory();
				}
			}
		}
		return instance;
	}

	public User getUserByName(String name) {
		User user = new NullUser(name);
		for (String n : NAME_LIMIT) {
			if (n.equals(name)) {
				user = new RealUser(name);
			}
		}
		return user;
	}
}
